//
//  ScimPinyin.h
//  cocoa_py
//  $Id: ScimPinyin.h 60 2010-08-07 22:00:18Z qiaolun $
//  Created by Qiao Lun on 6/21/10.
//  Copyright 2010 KK Group. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#include "scim.h"
#include "scim_phrase.h"
#include "scim_pinyin.h"
#include "scim_pinyin_phrase.h"
#include "scim_pinyin_global.h"
#include "scim_special_table.h"
#include "scim_native_lookup_table.h"
#include "scim_pinyin_smart_match.h"


@interface ScimPinyin : NSObject {

	PinyinGlobal         *m_pinyin_global;
	PinyinTable          *m_pinyin_table;
    PinyinPhraseLib      *m_sys_phrase_lib;
    PinyinPhraseLib      *m_user_phrase_lib;

    PinyinParser		 *m_pinyin_parser;

	String               m_inputed_string;
    WideString           m_preedit_string;
    WideString           m_converted_string;

    IConvert             m_iconv;
    IConvert             m_chinese_iconv;

    int                  m_keys_caret;
    int                  m_lookup_caret;	

    std::vector <PinyinParsedKey>          m_parsed_keys;

    std::vector < std::pair<int, Phrase> > m_selected_phrases;

    std::vector < std::pair<int, WideString> > m_selected_strings;

    std::vector <CharVector>   m_chars_cache;

    std::vector <PhraseVector> m_phrases_cache;

	NativeLookupTable    m_lookup_table;

	NSString	*encodingStr;
	
	uint32      m_dynamic_sensitivity;
	uint32      m_smart_match_level;
	uint32      m_max_user_phrase_length;
	
	time_t      m_last_time;
	time_t      m_save_period;

	NSString	*user_dir;
	NSString	*user_pinyin_table_path;
	NSString	*user_phrase_lib_path;
	NSString	*user_pinyin_phrase_lib_path;
	NSString	*user_pinyin_phrase_index_path;
}

@property (retain) NSString *encodingStr;

@property (retain) NSString *user_dir;
@property (retain) NSString *user_pinyin_table_path;
@property (retain) NSString	*user_phrase_lib_path;
@property (retain) NSString	*user_pinyin_phrase_lib_path;
@property (retain) NSString	*user_pinyin_phrase_index_path;

- (id) initWithEncoding:(NSString *)enc ;

- (NSString *) getInputedString ;
- (NSString *) getConvertedString ;

- (NSArray *) get_candidates ;

- (BOOL) loadTable ;
- (void) saveUserLibrary ;
- (void) reset ;
- (void) refresh ;

- (BOOL) inputString:(NSString *)str client:(id)sender ;
- (BOOL) lookup_select: (int) index client:(id)sender;
- (BOOL) post_process: (char) key client:(id)sender ;
- (BOOL) enter_hit :(id)sender;
- (BOOL) space_hit :(id)sender;
- (void) refresh_lookup_table:(int)len client:(id)sender ;
- (BOOL) lookup_page_up:(id)sender ;
- (BOOL) lookup_page_down:(id)sender ;
- (void) update_lookup_table:(id)sender ;
- (BOOL) erase:(BOOL) backspace client:(id)sender;

- (void) updateMarkedText:(id)sender;
- (void) commit_converted:(id)sender ;
- (void) commit_string:(WideString)wstr client:(id)sender;

- (void) calc_parsed_keys ;
- (int) calc_inputed_caret ;


- (int) inputed_caret_to_key_index: (int) caret ;
- (bool) has_unparsed_chars ;


- (void) calc_lookup_table: (int) invalid_pos ;
- (void) lookup_to_converted: (int) index ;
- (void) calc_preedit_string ;

- (void) store_selected_phrase: (int) caret sphrase:( const Phrase &)phrase stotal:(const WideString &)total ;
- (void) store_selected_string: (int) caret sstring:(const WideString &)str stotal: (const WideString &)total ;
- (void) dynamic_adjust_selected ;
- (Phrase) add_new_phrase: (const WideString &)phrase keys:(const PinyinParsedKeyVector &)pkeys ref:(bool) refresh ;
- (void) clear_selected: (int) clear_pos ;

@end
